package com.wyh.day05.work;

import java.util.Scanner;

/**
 * @author 王艺豪
 * @version 1.0
 */
public class work01 {
    public static void main(String[] args) {
        Function function = new Function();
        function.menu();
    }
}

//创建一个 功能类
class  Function {
    Scanner scanner = new Scanner(System.in);
    String username1 = "";
    String password1 = "";

    //菜单
    public void menu() {

        while (true) {
            System.out.println("=====菜单=====");
            System.out.println("1. 注册");
            System.out.println("2. 登录");
            System.out.println("3. 退出");
            System.out.println("请输入的你选择:");
            //定义一个变量，用于选择菜单
            int key = scanner.nextInt();
            switch (key) {
                case 1:
                    register(); //注册
                    break;
                case 2:
                    logon(); //登录
                    break;
                case 3:
                    exit(); //退出
                    return;
            }
        }
    }

    //注册
    public void register() {
        System.out.println("请输入用户名:");
        username1 = scanner.next();
        System.out.println("请输入密码:");
        password1 = scanner.next();
        System.out.println("注册成功");
    }

    //登录
    public void logon() {
        System.out.println("请输入用户名:");
        String username2 = scanner.next();
        System.out.println("请输入密码:");
        String password2 = scanner.next();
        if (username2.equals(username1) && password2.equals(password1)) {
            System.out.println("登录成功");
        } else if (username2.equals(username1) && !(password2.equals(password1))) {
            System.out.println("密码错误");
        } else {
            System.out.println("登录失败,你还没有注册");
        }
    }

    //退出
    public void exit() {
        System.out.println("退出成功...");
    }

}
